<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增讲座报告')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <style>
        .form-group{
            flex: 0 0 50%;
            box-sizing: border-box;
        }
       .card{
           display: flex;
           flex-wrap: wrap;
       }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-report-add">
        <div class="card">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">申请人：</label>
                <div class="col-sm-8">
<!--                    <input name="teacherName" class="form-control" type="text" required>-->
                    <input name="userId" class="form-control" type="hidden" th:value="*{sysUsers.userId}">
                    <input class="form-control" type="text" th:value="*{sysUsers.userName}" readonly>
<!--                    <select name="userId" class="form-control m-b" >-->
<!--                        <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${user.flag}"></option>-->
<!--                    </select>-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">讲座主题：</label>
                <div class="col-sm-8">
                    <input name="reportTheme" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">讲座题目：</label>
                <div class="col-sm-8">
                    <input name="reportSubject" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">主办单位：</label>
                <div class="col-sm-8">
                    <input name="hostUnit" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">讲座时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
<!--                        <input name="reportTime" autocomplete="off" class="form-control" placeholder="yyyy-MM-dd" type="text" required>-->
                        <input name="reportTime" autocomplete="off" class="form-control" placeholder="yyyy-MM-dd-HH-mm" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">讲座地点：</label>
                <div class="col-sm-8">
                    <input name="reportPlace" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">参与人数：</label>
                <div class="col-sm-8">
                    <input name="reportNumber" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">报告时长：</label>
                <div class="col-sm-8">
                    <input name="reportDuration" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类：</label>
                <div class="col-sm-8">
<!--                    <input name="reportClassify" class="form-control" type="text">-->
                    <select name="reportClassify" class="form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="reportIntegral : ${reportIntegralList}" th:text="${reportIntegral.classification}" th:value="${reportIntegral.id}"></option>
                    </select>
                </div>
            </div>

<!--        <div class="col-xs-6">-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">资料：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="reportUrl">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="reportUrl" name="file" type="file">
                    </div>
                </div>
            </div>
<!--        </div>-->


        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/report"
    $("#form-report-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            if ($("input[name='reportUrl']").val() === "")
                return $.modal.alertError("请上传附件");
            $.operate.saveTab(prefix + "/add", $('#form-report-add').serialize());
        }
    }

    // $("input[name='reportTime']").datetimepicker({
    //     format: "yyyy-mm-dd",
    //     minView: "month",
    //     autoclose: true
    // });

    $("input[name='reportTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii",
        minView: "hour",
        autoclose: true
    });

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload/jzbg', // 文件上传的URL
        maxFileCount: 1, // 最多允许上传1个文件
        autoReplace: true, // 自动替换已上传的文件
        allowedFileExtensions: ["pdf"], // 只允许上传PDF文件
        slugCallback: function (filename) {
            // 自定义文件名生成规则
            if ($("input[name='reportSubject']").val() === "") {
                $(".file-uploada").fileinput('clear'); // 清空文件选择
                $.modal.alertError("请先填写讲座题目"); // 弹出错误提示
                return false; // 阻止上传
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop(); // 获取文件扩展名
            const year = new Date().getFullYear(); // 获取当前年份
            const newName = year + "-" + $("input[name='reportSubject']").val() + "-" + "资料" + "." + fileExtension; // 生成新文件名
            return newName; // 返回新文件名
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        // 文件上传成功后的回调
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        // 文件被移除后的回调
        $("input[name='" + event.currentTarget.id + "']").val('')
    })

</script>
</body>
</html>